<?php
/**
 * 栏目管理页面
 *
 * @author Alen
 * @since 1.0.0 2013-10-3 sutroon
 */
class Page_ListAction extends AdmincpAction {
    //put your code here
    public function index(){
        
        // 设置页面导航
        $this->set_breadcrumb(array('栏目管理'=>'###','列表'=>'###'));
        
        // 设置页面标题
        $this->set_h1('栏目管理','在这里管理所有栏目');
        
        // 设置页面信息,如页面标题,meta信息等
        $this->set_page_info('栏目管理');
        
        $biz=new SoBizGeneral();        
        $pager_text='';
        $dataset=null;
        $biz->get_paging_data($pager_text, $dataset, request_numeric('page'), request_string('keyword'));
        
        $this->assign('pager',$pager_text);
        
        // 构建数据表格
        $this->uig->begin_table();
        $this->uig->add_thead('#','名称','日期','状态','管理');
        
        if($dataset){
            $bizc=new SoBizCommon();
            foreach($dataset as $row){
                $this->uig->add_trow($row['ID'],$row['Name'],$row['CreatedTime'],$bizc->switch_state(array('v'=>$row['State'],'group'=>array('0'=>'关闭','1'=>'正常'))),$this->get_control_linkbuttons($row['ID'],$row['Name'],'Page' ));
                $dataset2=$this->dm->select_arrayset('tgeneraldata', 'ParentID='.$row['ID']);
                if($dataset2){
                    foreach($dataset2 as $row2){
                        $this->uig->add_treerow($row2['ID'],'____'.$row2['Name'],$row2['CreatedTime'],'同上',$this->get_control_linkbuttons($row2['ID'],$row2['Name'],'Page' ));
                    }                    
                }
            }
        }
        $this->uig->end_table();
        $this->assign('table',$this->uig->get_text());
        
        // 显示模板
        $this->display();
    }
    
    public function delete(){        
        $id=request_numeric('id');
        if($id){            
            $this->dm->delete_records('tgeneraldata','ID='.$id);
            redirect('删除成功','?m=Page_List');        
        }
    }
    public function initdata(){
        
        $this->dm->tablename='tgeneraldata';
        $a=array(
            '企业信息'=>array('企业简介','联系我们','企业文化','成长里程','组织架构','招贤纳士','意见反馈','合作伙伴','法律声明')
            );
        foreach($a as $n => $arr){
            if(!$this->dm->exists(sprintf("ExTags='PAGE' and Name='%s'",$n))){
                $id=$this->dm->insert_record('', 'Name, ExTags, ParentID', sprintf("'%s', 'PAGE', 0",$n));
                foreach($arr as $v){
                    if(!$this->dm->exists(sprintf("ExTags='PAGE' and Name='%s'",$v))) $this->dm->insert_record('', 'Name, ExTags, ParentID, Value', sprintf("'%s', 'PAGE', %d, '请到后台编辑 %s 的内容'",$v,$id,$v));
                }
            }
        }
        redirect('初始化成功','?m=Page_List');
    }
}

?>
